package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.motion.widget.MotionLayout.TransitionListener;

public class MainActivity15 extends AppCompatActivity {

    private MotionLayout mMotionLayout;
    private ImageView mImage;
    private TextView mText;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity15.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main15 );
        initView();
        initViewAction();
    }

    private void initView() {

        mMotionLayout = (MotionLayout) findViewById( R.id.motionLayout );
        mImage = (ImageView) findViewById( R.id.image );
        mText = (TextView) findViewById( R.id.text );
    }

    private void initViewAction() {

        mMotionLayout.post( new Runnable() {
            @Override
            public void run() {

                mMotionLayout.setTransition( R.id.transition );
                mMotionLayout.transitionToEnd();
            }
        } );

        mMotionLayout.setTransitionListener( new TransitionListener() {
            @Override
            public void onTransitionStarted( MotionLayout motionLayout, int i, int i1 ) {

            }

            @Override
            public void onTransitionChange( MotionLayout motionLayout, int i, int i1, float v ) {

            }

            @Override
            public void onTransitionCompleted( MotionLayout motionLayout, int i ) {

                mMotionLayout.setProgress( 0 );
                mMotionLayout.setTransition( R.id.transition );
                mMotionLayout.transitionToEnd();
            }

            @Override
            public void onTransitionTrigger( MotionLayout motionLayout, int i, boolean b, float v ) {

            }
        } );
    }
}